package com.hm.hall.commons.service;

import com.alibaba.fastjson.JSON;
import com.hm.hall.commons.constans.GameConstans;
import com.hm.hall.commons.controller.req.MsgDeliverReq;
import com.hm.hall.commons.dao.GameOptLogMapper;
import com.hm.hall.commons.domain.GameOptLog;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * @author luhong E-mail: luhong@hoomic.com
 * @version 1.0
 * @date 创建时间：2017年2月7日 下午4:06:57
 * @parameter
 * @return
 * @since
 */
@Service
public class GameOptLogService {

    @Autowired
    GameOptLogMapper gameOptLogMapper;

    @Async
    public void insertOptLog(MsgDeliverReq req, GameConstans.GameType gameIdentifier) {
        GameOptLog record = new GameOptLog();
        record.setGameIdentifier(gameIdentifier.toString());
        record.setCreateTime(new Date());
        record.setOptType(req.getMsgType());
        record.setOthers(JSON.toJSONString(req));
        record.setUserId(req.getStubInfo().getUserId());
        gameOptLogMapper.insertSelective(record);
    }

    @Async
    public void insertSysOptLog(GameConstans.GameType gameIdentifier, String type, long userId, String desc) {
        GameOptLog record = new GameOptLog();
        record.setGameIdentifier(gameIdentifier.toString());
        record.setCreateTime(new Date());
        record.setOptType(type);
        record.setOthers(desc);
        record.setUserId(userId);
        gameOptLogMapper.insertSelective(record);
    }
}
